<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">
	</head>

	<body>
		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form test_edit" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label class="layui-form-label">视频状态</label>
								<div class="layui-input-block on_off"></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">视频分类</label>
								<div class="layui-input-inline" style="width: auto;">
									<input type="radio" name="type" value="1" title="公司介绍" checked="checked">
									<div class="layui-unselect layui-form-radio">
										<i class="layui-anim layui-icon"></i>
										<div>公司介绍</div>
									</div>
									<input type="radio" name="type" value="2" title="市场奖励">
									<div class="layui-unselect layui-form-radio layui-form-radioed">
										<i class="layui-anim layui-icon"></i>
										<div>市场奖励</div>
									</div>
									<input type="radio" name="type" value="3" title="考试专区">
									<div class="layui-unselect layui-form-radio layui-form-radioed">
										<i class="layui-anim layui-icon"></i>
										<div>考试专区</div>
									</div>
								</div>
							</div>
							<!-- <div class="layui-form-item">
								<label class="layui-form-label">客户端</label>
								<div class="layui-input-block icon_type"></div>
							</div> -->

							<div class="layui-form-item">
								<label class="layui-form-label">视频标题</label>
								<div class="layui-input-block">
									<input type="text" name="title" placeholder="请输入标题" autocomplete="off" lay-verify="required" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">赠送积分</label>
									<div class="layui-input-block">
										<input type="text" name="give_score" placeholder="请输入积分数量" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">点击量</label>
									<div class="layui-input-block">
										<input type="text" name="hits" placeholder="请输入点击量" autocomplete="off" class="layui-input">
									</div>
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">视频简介：</label>
								<div class="layui-input-block">
									<textarea placeholder="请输入视频简介" name="content" lay-verify="required" class="layui-textarea"></textarea>
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">是否推荐</label>
								<div class="layui-input-inline">
									<input type="radio" name="is_recommend" value="1" title="是">
									<div class="layui-unselect layui-form-radio layui-form-radioed"><i
											class="layui-anim layui-icon"></i>
										<div>是</div>
									</div><input type="radio" name="is_recommend" value="0" title="否"
										checked="checked">
									<div class="layui-unselect layui-form-radio"><i
											class="layui-anim layui-icon"></i>
										<div>否</div>
									</div>
								</div>
							</div>
							<div class="layui-form-item upvideo">
								<label class="layui-form-label">视频</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal upimgbtn"
										onclick="choose(3)">上传视频</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										预览视频：
										<div class="layui-upload-list upload_list" id="video_url">
											<ul class="show_img_ul" id="video_url"></ul>
										</div>
									</blockquote>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">视频封面</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(4)">上传图片</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="video_pic"></ul>
									</blockquote>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">视频文件</label>
								<div class="layui-input-block">
									<button type="button" class="layui-btn layui-btn-normal"
										onclick="choose(10)">上传文件</button>
									<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
										<ul class="show_img_ul" id="file_url"></ul>
									</blockquote>
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {}
			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate', 'layedit', 'rate'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form;
				var rate = layui.rate;
				var img_arr3 = [],
					img_arr4 = [],
					img_arr10 = [];
				//渲染
				var ins1 = rate.render({
					elem: '#score', //绑定元素
					half: true,
					value: _data.score,
					choose: function(value) {
						_data.score = value;
					}
				});
				on_off_show('radio');
				// icon_type_show('checkbox');
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.video_url = img_arr3.join(',');
					_data.video_pic = img_arr4.join(',');
					_data.file_url = img_arr10.join(',');
					var lock = false;
					layer.confirm('确定要提交数据？', function() {
						if (!lock) {
							lock = true
							loading();
							submitdata(server.sys_shop_video_edu_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});
				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
				};
				window.choose = function(data) {
					layer.open({
						type: 2,
						title: '上传图片',
						shadeClose: false,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['700px', '400px'],
						content: '../../model/up_report.html?type=' + data,
						end: function() {},
						success: function() {}
					});
				}
				window.getimg = function(data, type) {
					console.log('data',data)
					console.log('type',type)
					if (data) {
						switch (type) {
							case '10':
								createli(data, 'file_url', type)
								break;
							case '3':
								createli(data, 'video_url', type)
								break;
							case '4':
								createli(data, 'video_pic', type)
								break;
							default:
								break;
						}
					}
				}
				window.delimg = function(i, type, _self) {
					var _type = String(type)
					var lock = false
					layer.confirm('确定要删除图片？', function(index) {
						if (!lock) {
							lock = true
							switch (_type) {
								case '10':
									img_arr10.splice(i, 1)
									break;
								case '3':
									img_arr3.splice(i, 1)
									break;
								case '4':
									img_arr4.splice(i, 1)
									break;
								default:
									break;
							}
							$(_self).parent().remove();
							layer.close(index)
						}
					}, function() {
						layer.msg('取消操作');
					});
				}
				
				function createli(data, dom, type) {
					console.log(data)
					var lihtml = '';
					switch (type) {
						case '10':
							if (data.indexOf(',') == -1) {
								img_arr10.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr10.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr10.length; i++) {
								if(img_arr10[i].indexOf('.ppt') > -1 || img_arr10[i].indexOf('.pptx') > -1){
									lihtml += `<li class="show_img_li"><img src='../../../../img/ppt.png' ><p onclick="delimg(` + i + `,10,this)">删除</p></li>`
								} else if(img_arr10[i].indexOf('.pdf') > -1){
									lihtml += `<li class="show_img_li"><img src='../../../../img/pdf.png' ><p onclick="delimg(` + i + `,10,this)">删除</p></li>`
								} else if(img_arr10[i].indexOf('.txt') > -1){
									lihtml += `<li class="show_img_li"><img src='../../../../img/txt.png' ><p onclick="delimg(` + i + `,10,this)">删除</p></li>`
								} else if(img_arr10[i].indexOf('.doc') > -1 || img_arr10[i].indexOf('.docx') > -1){
									lihtml += `<li class="show_img_li"><img src='../../../../img/word.png' ><p onclick="delimg(` + i + `,10,this)">删除</p></li>`
								} else if(img_arr10[i].indexOf('.xls') > -1 || img_arr10[i].indexOf('.xlsx') > -1){
									lihtml += `<li class="show_img_li"><img src='../../../../img/excel.png' ><p onclick="delimg(` + i + `,10,this)">删除</p></li>`
								} else {
									lihtml += '<li class="show_img_li">' +
										'<img src=' + img_arr10[i] + ' >' +
										'<p onclick="delimg(' + i + ',10,this)">删除</p>' +
										'</li>'
								}
							}
							break;
						case '3':
							if (data.indexOf(',') == -1) {
								img_arr3.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr3.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr3.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<video controls="controls" id="video{{index}}" width="320" height="240"><source src=' + 
									img_arr3[i] + ' type="video/ogg" /><source src=' + img_arr3[i] +
									' video/mp4" /></video>' +
									'<p onclick="delimg(' + i + ',3,this)">删除</p>' +
									'</li>'
							}
							break;
						case '4':
							if (data.indexOf(',') == -1) {
								img_arr4.push(data)
							} else {
								for (var i = 0; i < data.split(',').length; i++) {
									img_arr4.push(data.split(',')[i])
								}
							}
							for (var i = 0; i < img_arr4.length; i++) {
								lihtml += '<li class="show_img_li">' +
									'<img src=' + img_arr4[i] + ' >' +
									'<p onclick="delimg(' + i + ',4,this)">删除</p>' +
									'</li>'
							}
							break;
						default:
							break;
					}
					$('#' + dom).html(lihtml);
				}
			});
		</script>
	</body>

</html>
